package cn.sunshine.controller;

import cn.sunshine.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {
    //需要配置Bean
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping(value = "/order/{id}")
    public User getById(@PathVariable Long id) {

        //目标资源路径：user的ip,user的端口，user的Controller路径
        String url = "http://localhost:1020/user/" + id;

        //发送http请求
        return restTemplate.getForObject(url, User.class);

    }
}
